package com.test.exam.dao;

import java.util.HashMap;
import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.test.exam.commons.PageHelper;
import com.test.exam.domain.Question;

@Repository
public class QuestionDao {
	private final String QUESTION_NS =
			"com.test.exam.mapper.QuestionMapper";
	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;
	
	// 조건 전체 반 row수
	public int getQuestionCountBySubjectIdx(int subjectIdx){
	//	System.out.println("dao subjectIdx:"+subjectIdx);
		HashMap map = new HashMap();
		map.put("subjectIdx", subjectIdx);
		return sqlSessionTemplate.selectOne(
				QUESTION_NS+".getQuestionCountBySubjectIdx", map);
	}

	//페이지 문제 목록
	public List<HashMap> getQuestionsByCurrentPage(PageHelper pageHelper, int subjectIdx){
		
		HashMap map = new HashMap();
		map.put("pageHelper", pageHelper);
		map.put("subjectIdx", subjectIdx);
		
		return sqlSessionTemplate.selectList(
				QUESTION_NS+".getQuestionsByCurrentPage",map);
	}
	
	public int addQuestion(Question question){
		return sqlSessionTemplate.insert(
				QUESTION_NS+".addQuestion", question);
	}

}























